package org.login.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.login.dao.UserInfoDao;
import org.login.entity.UserInfo;
import org.login.util.DbUtils;

public class UserInfoDaoImpl implements UserInfoDao{

	@Override
	public UserInfo selectUser(String name, String pass) {
		
		UserInfo userInfo = null ;
		
		String sql = "select * from userinfo where username=? and [password]=?" ;
		
		DbUtils dbUtils = new DbUtils() ;
		try {
			ResultSet rst = dbUtils.executeQuery(sql, name,pass) ;
			
			if(rst.next()) {
				int id = rst.getInt(1) ;
				String username = rst.getString(2);
				String tel = rst.getString(4);
				String sex = rst.getString(5);
				
				userInfo = new UserInfo();
				
				userInfo.setId(id);
				userInfo.setUsername(username);
				userInfo.setTel(tel);
				userInfo.setSex(sex);
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return userInfo;
	}



}
